import moment from "moment";
let formatDate = (value, type = "YYYY-MM-DD HH:mm:ss", is8 = false) => {
  if (!type) {
    type = "YYYY-MM-DD HH:mm:ss";
  }

  if (!value) {
    return "N/A";
  }
  return moment(value).format(type);
  // if (!is8) {
  //   return moment(value).format(type);
  // } else {
  //   return moment.utc(value).format(type);
  // }
};
export const testData = [];
// 生成随机数
function leftOpen(n, m) {
  var result = Math.random() * (m - n + 1) + n - 1;
  while (result < n) {
    result = Math.random() * (m - n + 1) + n - 1;
  }
  return Number(result.toFixed(3));
}

export const renderTestArr = num => {
  // 生成测试数据
  var start = new Date("2022-12-12T08:00:00"); // 设置开始时间
  var start2 = new Date("2022-12-12T18:11:00"); //
  var start3 = new Date("2022-12-12T18:53:30"); //2022-12-1218:53:30
  var start4 = new Date("2022-12-12T19:53:30"); //2022-12-1218:53:30
  var end = new Date("2022-12-12T23:00:00"); // 设置结束时间
  var chaochu_1 = new Date("2022-12-12T13:00:00"); // 设置开始时间
  var chaochu_2 = new Date("2022-12-12T13:05:00"); // 设置开始时间
  var timeArray = []; // 创建空的时间数组
  var timeArray2 = []; // 创建空的时间数组
  let meter1RunStageNO = 1; //阶段
  let meter1RealTemp = num;
  let meter2RealTemp = num;
  let meter3RealTemp = num;
  function renderTime() {
    if (start > end) {
      return;
    }
    if (start >= start4) {
      meter1RealTemp = leftOpen(860.5, 862.9);
      meter2RealTemp = leftOpen(860.5, 865.12);
      meter3RealTemp = leftOpen(860.5, 863.53);
    } else if (start >= start3) {
      meter1RealTemp += leftOpen(0.58, 1.97);
      meter2RealTemp += leftOpen(0.78, 1.77);
      meter3RealTemp += leftOpen(0.98, 1.57);
    } else if (start >= start2) {
      meter1RealTemp -= leftOpen(0.58, 1.97);
      meter2RealTemp -= leftOpen(0.78, 1.77);
      meter3RealTemp -= leftOpen(0.98, 1.57);
    } else {
      // 到五百的时候 开始保温
      if (
        meter1RealTemp >= 800 ||
        meter2RealTemp >= 800 ||
        meter3RealTemp >= 800
      ) {
        meter1RunStageNO = 2;
        meter1RealTemp = leftOpen(800.5, 802.9);
        meter2RealTemp = leftOpen(800.5, 805.12);
        meter3RealTemp = leftOpen(800.5, 803.53);
      } else {
        meter1RealTemp += leftOpen(1.58, 2.97);
        meter2RealTemp += leftOpen(1.78, 2.77);
        meter3RealTemp += leftOpen(1.98, 2.57);
      }
      if (chaochu_1 < start && chaochu_2 > start) {
        meter1RealTemp = leftOpen(811.5, 811.9);
      }
    }

    // 将当前时间添加到时间数组中
    // timeArray.push({
    //   eventDate: formatDate(start),
    //   metadata: {
    //     meter1RealTemp,
    //     meter2RealTemp,
    //     meter3RealTemp,
    //     meter1RunStageNO,
    //   },
    // });
    timeArray2.push([
      formatDate(moment(start, "YYYY-MM-DD HH:mm:ss")),
      meter1RealTemp
    ]);
    // 增加三十秒
    start.setSeconds(start.getSeconds() + 30);
    renderTime();
  }
  renderTime();
  return timeArray2;
};
